package org.linuxsogood.boot.misc;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author honway.liu
 * @date 2019-03-06 22:59
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class ImmutableTest {

    private static final Map<String, String> map1 = new HashMap<>();

    static {
        map1.put("a", "1");
        map1.put("b", "1");
        map1.put("c", "1");

    }


    public static void main(String[] args) {
        // map的引用不可再被修改,但是map里的值,是可以被修改的
        map1.put("a", "2");
        System.out.println(map1);

        /**
         * 将一个普通map变为不可变map, 该map里的值, 也不可被修改.
         */
        Map<String, String> map2 = Collections.unmodifiableMap(map1);
        map2.put("a", "1");
    }
}
